package com.cjm.one.webmanager.controller.goods;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.goods.dto.GoodsInfoDto;
import com.cjm.one.model.goods.entity.GoodsInfo;
import com.cjm.one.model.goods.vo.GoodsInfoVo;
import com.cjm.one.webmanager.service.goods.GoodsInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "2-商品信息管理")
@RequestMapping("/manager/goods/info")
public class GoodsInfoController {
    @Resource
    private GoodsInfoService goodsInfoService;
    @GetMapping("/list")
    public Result<Page<GoodsInfo>> pageList(@RequestParam(name = "current") Long current,
                                            @RequestParam(name = "size") Long size,
                                            @RequestParam(name = "name",required = false) String name,
                                            @RequestParam(name = "categoryId", required = false) Long categoryId) {
       return Result.ok(goodsInfoService.pageList(current, size, name, categoryId));
    }
    @GetMapping("/list/batch/{ids}")
    @Operation(summary = "批量查询")
    public Result<List<GoodsInfo>> listBatch(@PathVariable(name = "ids") Long[] ids){
        return Result.ok(goodsInfoService.listBatchByIds(ids));
    }

    @PostMapping
    @Operation(summary = "新增")
    public Result<Boolean> save(@RequestBody GoodsInfoDto goodsInfoDto){
        return Result.ok(goodsInfoService.saveGoodsInfo(goodsInfoDto));
    }
    @DeleteMapping("/{id}")
    @Operation(summary = "根据id删除")
    public Result<Boolean> remove(@PathVariable("id") Long id){
        return Result.ok(goodsInfoService.removeById(id));
    }
    @PutMapping
    @Operation(summary = "修改")
    public Result<Boolean> update(@RequestBody GoodsInfoDto goodsInfoDto){
        return Result.ok(goodsInfoService.updateGoodsInfo(goodsInfoDto));
    }
    @GetMapping("/{id}")
    @Operation(summary = "根据id查询")
    public Result<GoodsInfoVo> getById(@PathVariable("id") Long id){
        return Result.ok(goodsInfoService.getGoodsInfoVoById(id));
    }
}
